package com.mk.admin.service.impl;

import com.mk.admin.mapper.QuestionMapper;
import com.mk.admin.model.ResultDto;
import com.mk.admin.model.entity.QuestionEntity;
import com.mk.admin.model.vo.QuestionVo;
import com.mk.admin.service.QuestionService;
import com.mk.admin.util.DateTool;
import com.mk.admin.util.JSONCopy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public ResultDto select(QuestionVo vo) {
        QuestionEntity entity = JSONCopy.copy(vo, QuestionEntity.class);
        return ResultDto.data(questionMapper.count(entity), questionMapper.select(entity));
    }

    @Override
    public ResultDto add(QuestionVo questionVo) {
        QuestionEntity entity = JSONCopy.copy(questionVo, QuestionEntity.class);
        entity.setCreateTime(DateTool.format());
        return ResultDto.data(questionMapper.insert(entity));
    }

    @Override
    public ResultDto update(QuestionVo questionVo) {
        QuestionEntity entity = JSONCopy.copy(questionVo, QuestionEntity.class);
        return ResultDto.data(questionMapper.updateById(entity));
    }

    @Override
    public ResultDto delete(int id) {
        return ResultDto.data(questionMapper.deleteById(id));
    }

    @Override
    public ResultDto status(int id) {
        return ResultDto.data(questionMapper.status(id));
    }

}
